using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StatsDisplay : MonoBehaviour
{
	public UIScrollView view;

	public UITable table;

	public UIWidget matchSummary;

	public AnimationCurve moveAnimationCurve;

	public StatsButton buttonPrefab;

	private List<StatsButton> buttons = new List<StatsButton>();

	public Vector3 moveFrom;

	public Vector3 moveTo;

	public UISprite bckDarken;

	public UIWidget touchToContinue;

	private Action onComplete;


    public void ShowMatchSummary(TableTennisClassic clasic, Action onComplete)
	{
		this.onComplete = onComplete;
		GameStats gameStats = clasic.gameStats;
		int num = 0;
		if (num >= buttons.Count)
		{
			StatsButton component = NGUITools.AddChild(table.gameObject, buttonPrefab.gameObject).GetComponent<StatsButton>();
			component.gameObject.name = GGFormat.IndexName(num);
			buttons.Add(component);
		}
		num++;
		StatsButton statsButton = buttons[0];
		string player1Name = MatchParameters.InitParameters.player1Name;
		string player2Name = MatchParameters.InitParameters.player2Name;
		statsButton.Init(GGFormat.FirstName(player1Name).ToUpper(), clasic.scoreString, GGFormat.FirstName(player2Name).ToUpper());
		for (int i = 0; i < gameStats.gameStats.Count; i++)
		{
			GameStats.GameStatBase gameStatBase = gameStats.gameStats[i];
			if (gameStatBase.shouldDisplay)
			{
				if (num >= buttons.Count)
				{
					StatsButton component2 = NGUITools.AddChild(table.gameObject, buttonPrefab.gameObject).GetComponent<StatsButton>();
					component2.gameObject.name = GGFormat.IndexName(num);
					buttons.Add(component2);
				}
				statsButton = buttons[num];
				statsButton.Init(gameStatBase);
				num++;
			}
		}
		for (int j = gameStats.gameStats.Count; j < buttons.Count; j++)
		{
			buttons[j].gameObject.SetActive(false);
		}
		base.gameObject.SetActive(true);
		table.Reposition();
		for (int k = 0; k < num; k++)
		{
			statsButton = buttons[k];
			statsButton.GetComponent<UIWidget>().alpha = 0.01f;
		}
		AnimateIn();
		TableTennisMatchController match = clasic.match;
		if (match != null)
		{
			TableTennisMatchControllerIntro tableTennisMatchControllerIntro = TableTennisMatchControllerIntro.Create(match);
			match.starter.cameraController.ChangeGameplayInterval(TTCameraBehaviour.GameplayIntervalType.IntroCamera, default(TTCameraOptions));
			tableTennisMatchControllerIntro.StartServe(tableTennisMatchControllerIntro.GetPlayer(0));
		}
	}

	private void AnimateIn()
	{
		StopAllCoroutines();
		StartCoroutine(DoAnimateIn());
	}

	private IEnumerator DoAnimateIn()
	{
		UITools.SetActive(touchToContinue, false);
		StartCoroutine(UIAnimTools.DoFadeFromTo(bckDarken, 0.01f, 0.5f, 0.25f));
		yield return StartCoroutine(UIAnimTools.DoMoveFromTo(matchSummary.cachedTransform, moveFrom, moveTo, 0.75f, moveAnimationCurve));
		float delay = 0f;
		for (int i = 0; i < buttons.Count; i++)
		{
			StatsButton statsButton = buttons[i];
			UITools.SetActive(statsButton, true);
			statsButton.AnimateIn(delay);
			table.Reposition();
			delay += 0.1f;
		}
		table.Reposition();
		yield return new WaitForSeconds(1f);
		UITools.SetActive(touchToContinue, true);
	}

	public void OnDoneClick()
	{
		if (touchToContinue.gameObject.activeSelf)
		{
			UITools.SetActive(base.gameObject, false);
			if (onComplete != null)
			{
				onComplete();
			}
		}
	}
}
